const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

async function testSuggestionsAPI() {
  console.log('测试建议API响应...');
  
  // 测试建议API - 不带参数，无认证
  try {
    const response1 = await fetch('http://localhost:3000/api/suggestions');
    if (response1.status === 401) {
      console.log('建议API需要认证 (401)');
    } else {
      const data1 = await response1.json();
      console.log('建议API (无参数):', data1.length, '条记录');
      if (data1.length > 0) {
        console.log('第一条建议:', data1[0]);
      }
    }
  } catch (error) {
    console.error('建议API错误:', error.message);
  }
  
  // 测试建议API - 带submitter参数，无认证
  try {
    const response2 = await fetch('http://localhost:3000/api/suggestions?submitter=admin');
    if (response2.status === 401) {
      console.log('建议API需要认证 (401)');
    } else {
      const data2 = await response2.json();
      console.log('建议API (submitter=admin):', data2.length, '条记录');
      if (data2.length > 0) {
        console.log('第一条建议:', data2[0]);
      }
    }
  } catch (error) {
    console.error('建议API错误:', error.message);
  }
  
  // 测试建议API - 带submitter参数（匿名用户），无认证
  try {
    const response3 = await fetch('http://localhost:3000/api/suggestions?submitter=匿名用户');
    if (response3.status === 401) {
      console.log('建议API需要认证 (401)');
    } else {
      const data3 = await response3.json();
      console.log('建议API (submitter=匿名用户):', data3.length, '条记录');
      if (data3.length > 0) {
        console.log('第一条建议:', data3[0]);
      }
    }
  } catch (error) {
    console.error('建议API错误:', error.message);
  }
}

testSuggestionsAPI(); 